package com.sky.mapper;

import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealDishMapper {

    /**
     * 根据菜品id查询套餐id
     * @param dishIds
     * @return
     */
    List<Long> getSetMealDishIds(List<Long> dishIds);

    /**
     * 插入套餐中的菜品
     * @param setmealDishes
     */
    void insertMealBatch(List<SetmealDish> setmealDishes);

    /**
     * 删除套餐后对应的套餐菜品关系表也需要删除
     * @param SetMealIds
     */
    void deleteBySetMealIds(List<Long> SetMealIds);

    /**
     * 根据套餐id查询菜品
     * @param setMealId
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{setMealId}")
    List<SetmealDish> getSetMealDishByMealId(Long setMealId);

    /**
     * 根据一个setMealId删除对应的菜品
     * @param setmeal_id
     */
    @Delete("delete from setmeal_dish where setmeal_id = #{setmeal_id}")
    void deleteBySetMealId(Long setmeal_id);

    /**
     * 查询套餐中菜品停售的菜品数量
     * @param id
     * @return
     */
    @Select("select count(*)\n" +
            "from setmeal_dish s,dish d\n" +
            "where s.setmeal_id = #{id} and d.id = s.dish_id and d.status = 0;")
    int getBanned(Long id);
}
